package com.universest.swordholder.ui.widget

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

@Composable
fun EnsureDialog(
    text: String,
    onEnsureOrCancel: (Boolean) -> Unit = {},
) {
    CardDialog(onDismissRequest = {}) {
        Column(
            modifier = Modifier.padding(top = 15.dp, start = 15.dp, end = 15.dp),
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            Text(text = text)
            Row(verticalAlignment = Alignment.CenterVertically) {
                TextButton(onClick = { onEnsureOrCancel(true) }) {
                    Text(text = "确定")
                }
                Box(modifier = Modifier.weight(1f))
                TextButton(
                    onClick = { onEnsureOrCancel(false) },
                ) {
                    Text(text = "取消")
                }
            }
        }
    }
}

@Composable
@Preview
fun EnsureDialogPreview() {
    EnsureDialog(text = "确定删除吗？")
}